package com.lei.day02rikao;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText et1;
    private Button bt_fsxx;
    private Button bt_fslw;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        et1 = (EditText) findViewById(R.id.et1);
        bt_fsxx = (Button) findViewById(R.id.bt_fsxx);
        bt_fslw = (Button) findViewById(R.id.bt_fslw);

        bt_fsxx.setOnClickListener(this);
        bt_fslw.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_fsxx:
                submit();
                Toast.makeText(this, ""+et1.getText().toString().trim(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.bt_fslw:
                Toast.makeText(this, "礼物发送成功", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    private void submit() {
        // validate
        String et1String = et1.getText().toString().trim();
        if (TextUtils.isEmpty(et1String)) {
            Toast.makeText(this, "请输入要发送的文字", Toast.LENGTH_SHORT).show();
            return;
        }

        // TODO validate success, do something


    }
}
